import {createStore, applyMiddleware} from 'redux' // applyMiddleware 可以自己实现
import combinedReducer from './reducers'
import logger from './logger-middleware'
import promise from './promise-middleware'
import thunk from './thunk-middleware'
import {routerMiddleware} from 'connected-react-router'
import { history } from '../example/redux/connected-react-router'
import createSagaMiddleware from 'redux-saga'
import rootSaga from './saga'
// 仓库只有一个 state只有一份
// 分开写 combineReducers

// applyMiddleware   还有实现多个中间件组合   compose
// function applyMiddleware(logger) {
//   return function (createStore) {
//     return function(reducer, preloadedState) {
//       let store = createStore(reducer, preloadedState)
//       let dispatch;
//       let middlewareAPI = {
//         getState: store.getState,
//         dispatch: (action) => dispatch(action)
//       }
//       dispatch = logger(middlewareAPI)(store.dispatch)
//       return {
//         ...store,
//         dispatch
//       }
//     }
//   }
// }

let sagaMiddleware = createSagaMiddleware()

let store = applyMiddleware(sagaMiddleware, routerMiddleware(history), promise, thunk, logger)(createStore)(combinedReducer)

sagaMiddleware.run(rootSaga)

export default store





